package com.culture.config.controller;

import java.util.List;

import javax.validation.Valid;

import com.culture.config.common.model.ResponseData;
import com.culture.config.common.util.ResponseUtil;
import com.culture.config.model.po.*;
import com.culture.config.model.vo.*;
import com.culture.config.service.InstanceService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api
@Slf4j
@RestController
@RequestMapping({"/api/instances"})
public class InstancesController extends BaseController {
    @Autowired
	private InstanceService instanceService;   
   
    @ApiOperation("instances page")
    @PostMapping(path = "/page")
    public ResponseData<List<AppInstanceVO>> page(@RequestBody @Valid AppInstancePagePO param) {
        log.info("page:{}",param);       
        return ResponseUtil.successPage(this.instanceService.page(param));
    }

    @ApiOperation("instances proxy")
    @PostMapping(path = "/proxy")
    public ResponseData<AppInstanceProxyVO> proxy(@RequestBody @Valid AppInstanceProxyPO param) {
        log.info("proxy:{}",param);
        return ResponseUtil.success(this.instanceService.proxy(param));
    }
    
    @ApiOperation("instances refresh")
    @PostMapping(path = "/refresh")
    public ResponseData<String> refresh(@RequestBody @Valid AppInstanceRefreshPO refreshPO) {
        log.info("refresh:{}",refreshPO);
        this.instanceService.refreshConfiguration(refreshPO);
        return ResponseUtil.ok();
    }
}
